package com.bw.liuyushan.zhuangao4_weektest2.MVP.Presenter;

import com.blankj.utilcode.util.ToastUtils;
import com.bw.liuyushan.mvp_lib.Presenter.BasePresenter;
import com.bw.liuyushan.mvp_lib.Presenter.IPresenter;
import com.bw.liuyushan.zhuangao4_weektest2.Entity.GiftBean;
import com.bw.liuyushan.zhuangao4_weektest2.Entity.UserBean;
import com.bw.liuyushan.zhuangao4_weektest2.Entity.VideoBean;
import com.bw.liuyushan.zhuangao4_weektest2.MVP.Contrack.IContrackTest;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * ZhuanGao4_WeekTest2
 * file name is : BasePresenterTest
 * created by Ender on 2021/8/23 8:28.
 * author : 刘雨杉
 * Describe(作用):
 */
public class BasePresenterTest extends BasePresenter<IContrackTest.C_ModelTest, IContrackTest.C_ViewTest> implements IPresenter {
    Disposable disposable;//RxJava内存泄露处理
    public BasePresenterTest(IContrackTest.C_ModelTest im, IContrackTest.C_ViewTest iv) {
        super(im, iv);
    }
    public void mpVideo(String url){
        im.askVideo(url, new Observer<VideoBean>() {
            @Override
            public void onSubscribe(Disposable d) {
                disposable = d;//RxJava内存泄露处理
            }

            @Override
            public void onNext(VideoBean videoBean) {
                iv.ShowVideo(videoBean);
            }

            @Override
            public void onError(Throwable e) {
                ToastUtils.showShort("请求数据失败");
            }

            @Override
            public void onComplete() {

            }
        });
    }
    public void mpLogin(String username, String password){
        im.asklogin(username, password, new Observer<UserBean>() {
            @Override
            public void onSubscribe(Disposable d) {
                disposable = d;//RxJava内存泄露处理
            }

            @Override
            public void onNext(UserBean userBean) {
                iv.ShowLogin(userBean);
            }

            @Override
            public void onError(Throwable e) {
                ToastUtils.showShort("请求数据失败");
            }

            @Override
            public void onComplete() {

            }
        });
    }
    public void mpReg(String username, String password,String repassword){
        im.askreg(username, password, repassword, new Observer<UserBean>() {
            @Override
            public void onSubscribe(Disposable d) {
                disposable = d;//RxJava内存泄露处理
            }

            @Override
            public void onNext(UserBean userBean) {
                iv.ShowReg(userBean);
            }

            @Override
            public void onError(Throwable e) {
                ToastUtils.showShort("请求数据失败");
            }

            @Override
            public void onComplete() {

            }
        });
    }
    public void mpGift(){
        im.askGift(new Observer<GiftBean>() {
            @Override
            public void onSubscribe(Disposable d) {
                disposable = d;
            }

            @Override
            public void onNext(GiftBean giftBean) {
                iv.ShowGift(giftBean);
            }

            @Override
            public void onError(Throwable e) {
                ToastUtils.showShort("请求礼物失败");
            }

            @Override
            public void onComplete() {

            }
        });
    }
}
